#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <glob.h>

#define BUFFSIZE 1024
#define PAT "*"

void l_display(char* path){
  printf("display -l mode\n");
  struct stat *statbuf;
  glob_t globres;
  int err = 0;

  err = glob(PAT, 0, NULL, &globres);
  if(err){
    exit(1);

  }
  for(int i=0; i < globres.gl_pathc; i++){
    stat(globres.gl_pathv[i], statbuf);
    printf("%d  %u  %u %s \n",(int)statbuf->st_nlink, statbuf->st_uid, statbuf->st_gid,globres.gl_pathv[i]);
  }


  

}

int main(int argc, char **argv){
  char cwdbuf[BUFFSIZE];
  getcwd(cwdbuf, sizeof(cwdbuf));

  if(argc < 2){    //当前目录下做ls查询
    struct stat *statbuf;
    glob_t globres;
    int err = 0;
    // printf("current working directory: %s\n",cwdbuf);
    
   // stat(, statbuf);
   
    err = glob(PAT, 0, NULL, &globres);
    if(err){
      printf("Error code = %d \n",err);
      exit(1);
    }
    for(int i = 0; i < globres.gl_pathc; i++ ){
      printf("%s  ", globres.gl_pathv[i]);
    }
    puts("");
  }
  else if(argc>1) {
    int c = 0;
    while(1){
      c = getopt(argc, argv, "alin");
      if(c < 0){
        break;
      }
      switch(c){
        case 1:
          
          break;
        case 'l':
          l_display(cwdbuf);
          break;
        case 'a':

          break;
        case 'i':

          break;

      }
    }

  }











  return 0;
}
